<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    /*  
    异步操作 => 等异步有结果之后改变状态
    var p = new Promise((resolve, reject) => {
         setTimeout(() => {
             resolve(1);
         }, 1000)
     })
     console.log(p);  // {<pending>:undefined}   1s后会变为 {<fulfilled>:1} 
 
     p.then((res) => {
         console.log("fulfilled", res);
     }).catch(res => {
         console.log("rejected", res);
     }) */


    // 同步代码 => Promise实例创建过程中立即改变状态\
    // Promise中,then()和catch()接收的回调函数执行时,也是异步的(异步任务)  => 1 3 2
    var p = new Promise((resolve, reject) => {
        console.log(1);
        resolve(1);
    })
    // console.log(p);  // {<fulfilled>:1} 

    p.then((res) => {
        // console.log("fulfilled", res);
        console.log(2);
    }).catch(res => {
        console.log("rejected", res);
    })

    console.log(3);


</script>

</html>